package com.lagou.StageOne.Module4.Assignment.Assignment2;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Copy_Folders {

    public static void Copy(String path1, String path2) {
        File file1 = new File(path1);
        File file2 = new File(path2);
        if (!file1.exists()) {
            System.out.println("目录不存在！");
            return;
        }

        if (!file2.exists()) {
            file2.mkdirs();
            System.out.println(file2 + "  复制成功");
        }



        //创建一个线程池
        ExecutorService service= Executors.newFixedThreadPool(10);

        for (File f :file1.listFiles()){
            service.submit(() -> {
                if (f.isFile()){
                    CopyFile.Copy(f.getAbsolutePath(), file2.getAbsolutePath() + "/" + f.getName());
                    System.out.println(f.getName()+  "复制成功");
                }else {
                    Copy_Folders.Copy(f.getAbsolutePath(), file2.getAbsolutePath() + "/" + f.getName());
                }
            });

        }

        service.shutdown();
    }
}